package com.ferdict;

import java.util.Currency;

import org.json.JSONArray;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class CommentsActivity extends Activity /* implements OnClickListener */{
	private static final String tag = "CommentsActivity";

	private String[] commentsStringArray;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.comments);

		getCommentsByOutfitId(getIntent().getExtras().getLong("outfitId"));
		((ListView) findViewById(R.id.list_view_id_comments))
				.setAdapter(new ArrayAdapter(this, R.layout.list_view_comments,
						commentsStringArray));
		// findViewById(R.id.button_id_close_comments).setOnClickListener(this);
	}

	// // @Override
	// public void onClick(View v) {
	// switch (v.getId()) {
	// case R.id.button_id_close_comments:
	// finish();
	// break;
	// }
	// }

	void getCommentsByOutfitId(long id) {
		try {
			String jsonList = RestClient.doGet(Constants.SERVER,
					com.ferdict.Constants.PORT, Constants.COMMENTS_URL + "?id="
							+ id);

			Log.w(tag, "JSON STR = " + jsonList);
			JSONArray commentsJsonArray = new JSONArray(jsonList);
			commentsStringArray = new String[commentsJsonArray.length()];
			for (int i = 0; i < commentsJsonArray.length(); i++) {
				commentsStringArray[i] = (i + 1) + ") "
						+ commentsJsonArray.get(i).toString();
			}
		} catch (Exception e) {
			Log.e(tag, String.format(
					"Could not get a list of comments for Outfit(id=%d)!", id),
					e);
		}
	}
}